package cn.com.headfree.mouldshow.dao.impl;

import cn.com.headfree.entity.TEmpBaseInfo;
import cn.com.headfree.mouldshow.dao.UserDataInfoDao;
import cn.com.headfree.vo.BusinessIdsVo;
import cn.com.headfree.vo.file.DealFileVo;
import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.util.StringUtil;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;

@Repository("userDataInfoDao")
public class UserDataInfoDaoImpl extends BaseDaoImpl<TEmpBaseInfo> implements UserDataInfoDao {

	@Override
	public BusinessIdsVo getBaseInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id " +
                " from t_emp_base_info t where t.erp_no= ?  and  t.is_valid='0' and t.del_sign = '0' ";
		return this.findUnique(BusinessIdsVo.class, sql, new Object[] { erpNo });
	}

	@Override
	public List<BusinessIdsVo> getProTecInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_pro_tec_info t " +
                " where t.is_valid='0'  and t.del_sign = '0' AND t.erp_no= ?";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getSkillLevelInfoByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_skill_level_info t " +
                " where t.is_valid='0' and t.del_sign = '0' AND t.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getTSdtTutorPrentInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_sdt_tutor_prent_info t " +
				" where t.is_valid='0'  and t.del_sign = '0' AND t.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getExpertTitleInfoByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_expert_title_info t " +
                " where t.is_valid='0' and t.del_sign = '0' AND t.erp_no= ?  ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getAcadeAchiveInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_acade_achive_info t " +
				" left join t_part_rank r on t.id = r.item_id " +
				" where  r.item_type='12' and t.is_valid='0'and t.del_sign = '0' AND r.erp_no= ? ";
		List<Object> arryList = new ArrayList<Object>();
        arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getStandInfoByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_stand_info t " +
				" left join t_part_rank r on r.item_id=t.id " +
				" where  r.item_type='13' and  t.is_valid='0' and t.del_sign = '0' AND r.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getPatentInfoByErpNo(String erpNo) {
		String sql = "   select t.id as business_id from t_patent_info t " +
				" left join t_part_rank r on r.item_id=t.id " +
				" where r.item_type='14'  and  t.is_valid='0' and t.del_sign = '0' AND r.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getTecInnovInfoByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_tec_innov_info t " +
				"  left join t_part_rank r on r.item_id = t.id " +
				" where  r.item_type='15' and  t.is_valid='0' and t.del_sign = '0' AND r.erp_no= ? " ;
		StringBuilder sqlBuilder = new StringBuilder(sql);
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getTecManInnovByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_tec_man_innov t " +
				" left join t_part_rank r on r.item_id=t.id " +
				" where r.item_type='16' and  t.is_valid='0' and t.del_sign = '0' AND r.erp_no= ? " ;
		List<Object> arryList = new ArrayList<Object>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getProjAchieveInfoByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_proj_achieve_info t" +
				" left join t_part_rank r on r.item_id=t.id " +
				" where r.item_type='17' and  t.is_valid='0' and t.del_sign = '0' AND r.erp_no= ? " ;
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getRotationInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_rotation_info t " +
				" where t.is_valid='0'  and t.del_sign = '0' AND t.erp_no= ? ";
		List<Object> arryList = new ArrayList<Object>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getHonnorInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_honor_info t " +
                " where t.is_valid='0'  and t.del_sign = '0' AND t.erp_no= ? ";
		List<Object> arryList = new ArrayList<Object>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getEducateInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_educate_info t " +
                " where t.is_valid='0' and t.del_sign = '0' AND (t.is_employ_educ = '0' or t.is_employ_educ is null or ((t.is_employ_educ = '1') and t.educ_name<40)) AND t.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getContiStudyInfoByErpNo(String erpNo) {
		String sql = " select t.id as business_id from t_conti_study_info t " +
				" where t.is_valid='0'  and t.del_sign = '0' and t.type = '01' AND t.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	@Override
	public List<BusinessIdsVo> getContestInfoByErpNo(String erpNo) {
		String sql = "  select t.id as business_id from t_contest_info t " +
				" where t.is_valid='0' and t.del_sign = '0' AND t.erp_no= ? ";
		List<String> arryList = new ArrayList<String>();
		arryList.add(erpNo);
		return this.findAllBySQL(BusinessIdsVo.class, sql, null, false, arryList.toArray());
	}

	public List<DealFileVo> getFilesByBusinessId(String businessId, String businessNode) {
		StringBuilder sqlBuilder = new StringBuilder(
				"select business_id,file_id,file_name,business_node,business_type_id,order_num ");
		sqlBuilder.append(" from t_file where 1=1 ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		if (!StringUtil.isNullOrEmpty(businessId)) {
			sqlBuilder.append(" and business_id=?");
			arrayList.add(businessId);
		}
		if (!StringUtil.isNullOrEmpty(businessNode)) {
			sqlBuilder.append(" and business_node=?");
			arrayList.add(businessNode);
		}
		sqlBuilder.append(" order by order_num ");
		return this.findAllBySQL(DealFileVo.class, sqlBuilder.toString(), null, false,arrayList.toArray());
	}

}
